<template>
	<view class="setPassword">
	<view class="box">
		<view class="list">
			<text class="list-left">新密码:</text>
			<view class="list-input-box">
				<input class="list-input" type="password" maxlength="6" placeholder="请输入新密码" :value="password"
					@input="inputPass" placeholder-class="pl"></input>
			</view>
		</view>
		<view class="list">
			<text class="list-left">确认密码:</text>
			<view class="list-input-box">
				<input class="list-input" type="password" maxlength="6" placeholder="再次输入密码" :value="rePass"
					@input="inputRePass" placeholder-class="pl"></input>
			</view>
		</view>
		<view class="tips">该密码为会员余额支付密码，并非微信支付密码</view>
		<view class="tips" style="color:#666;margin: 20rpx 0;padding-bottom: 20rpx;">初始密码为手机号后6位</view>
		
	</view>
	<view>
		<block v-if="password.length&&password==rePass">
			<view class="setTemporarily" @tap="toSet(2)">确认设置</view>
		</block>
		<view v-else class="setTemporarily btnDisabled">确认设置</view>
		<view class="notSetTemporarily" @tap="toSet(1)">暂不设置</view>
	</view>
	</view>
</template>

<script>
	var app = getApp().globalData;
	export default {
		name: 'setPassword',
		data() {
			return {
				vipId:'',
				password:'',
				rePass:''
			}
		},
		onLoad(options){
			let vipId = options.vipId
			if(vipId){
				this.vipId = vipId
			}
		},
		methods: {
			/**
			 * 输入密码
			 */
			inputPass: function(e) {
				var num = e.detail.value;
				num = num.replace(/^[0]|\D/, '');
				this.setData({
					password: num
				});
			},
			
			
			/**
			 * 再次输入密码
			 */
			inputRePass: function(e) {
				var num = e.detail.value;
				num = num.replace(/^[0]|\D/, '');
				this.setData({
					rePass: num
				});
			},
			
			// 设置密码
			toSet(type){
				if(type==1){
					uni.navigateBack({delta:1})
				}else {
					let _this = this
					let password = _this.password
					app.sendRequest({
						url: '/MerInterface/passwordSave',
						data:{
							id: _this.vipId,
							password: password
						},
						success:function({status,message}){
							if(status==1){
								uni.showToast({
									title: '设置密码成功',
									duration:1000
								})
								setTimeout(() => {
									uni.navigateBack({
										delta:1
									})
								},1000)
							}else {
								uni.showToast({
									title: message,
									icon:'none'
								})
							}
						}
					})
				}
			},
		}
	}
</script>

<style >
	@import "../../order/vipPassword/vipPassword.css";
	.setPassword {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.setTemporarily {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 690rpx;
		height: 90rpx;
		background: linear-gradient(to right, #ff948a, #ff5c6d);
		font-size: 32rpx;
		color:#fff;
		margin: 20rpx 30rpx;
		border-radius: 50rpx;
	}
	.notSetTemporarily {
		color: #666;
		margin-top: 20rpx;
		text-align: center;
	}
	.btnDisabled {
		background: #eee;
		color:#bbb;
	}
</style>
